package page;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

public class BaseSqlMakerImpl implements QueryStringMakerService {

	List fieldList;
	String sql="";
	String tableName="";
	public void setTableName(String tableName){
		this.tableName=tableName;
	}
	public void setFieldList(List list){
		this.fieldList=list;
	}
	private String makeBaseSql(){
		String tmp="";
		if(this.fieldList!=null){
			tmp="select ";
			
			for(int i=0;i<fieldList.size();i++){
				tmp+=fieldList.get(i);
				if(i!=fieldList.size()-1)
					tmp+=",";
			}
			tmp+=" from "+this.tableName;
		}
		return tmp;
	}
	//鍏佽瀛愮被缁ф壙骞舵敼鍐欒鏂规硶
	protected String makeConditionStr(HttpServletRequest request){
		String condition="";
		if(request!=null){
			
		}
		return condition;
	}
	//SqlMakerService鎺ュ彛鏂规硶
	public String makeSQL(HttpServletRequest request) {
		// TODO Auto-generated method stub
		String baseStr=makeBaseSql();
		String conditionConst=" where 1=1 ";
		String conditionStr=makeConditionStr(request);
		sql=baseStr+conditionConst+conditionStr;
		return sql;
	}
	
//	SqlMakerService鎺ュ彛鏂规硶
	public String getFieldName(int fieldIndex) {
		// TODO Auto-generated method stub
		String fieldName="";
		if(this.fieldList!=null){
			if(fieldIndex<fieldList.size()){
				fieldName=(String) fieldList.get(fieldIndex);
			}			
		}
		return fieldName;
	}
}
